/**
 * 添加或者修改页面
 */
var ZxHuopinInfoDlg = {
    data: {
        pid: "",
        pName: "",
        code: "",
        name: "",
        zhujima: "",
        btyZxKemuId: "",
        btyZxKemuIdView: "",
        status: "",
        statusView: "",
        delFlag: "",
        createUser: "",
        createUserName: "",
        createTime: "",
        updateUser: "",
        updateUserName: "",
        updateTime: "",
        company: "",
        companyView: "",
        srcType: "",
        srcValue: ""
    }
};

layui.use(['form', 'admin', 'ax','layer'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/dgdzxHuopin/addItem", function (data) {
            if (data.code == 1) {
                Feng.error("添加失败!" + data.message);
                return;
            }
            Feng.success("添加成功！");
            window.location.href = Feng.ctxPath + '/dgdzxHuopin'
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/dgdzxHuopin'
    });

    // 所属科目
    $('#btyZxKemuIdView').click(function () {
        var formName = encodeURIComponent("parent.ZxHuopinInfoDlg.data.pName");
        var formId = encodeURIComponent("parent.ZxHuopinInfoDlg.data.pid");
        var treeUrl = encodeURIComponent("/zxKemu/tree");

        layer.open({
            type: 2,
            title: '父级名称',
            area: ['300px', '400px'],
            content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
            end: function () {
                $("#btyZxKemuId").val(ZxHuopinInfoDlg.data.pid);
                $("#btyZxKemuIdView").val(ZxHuopinInfoDlg.data.pName);
            }
        });
    });
});